package com.superteam.zzl.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;
import com.superteam.zzl.activity.ImageActivity;
import com.superteam.zzl.activity.R;
import com.superteam.zzl.activity.databinding.ActivityImageVpBinding;

import java.util.List;

/**
 * Created by Administrator on 2017/1/12.
 */

public class ImageActivityAdapter extends BasePagerAdapter<String> {

    private View[] views;
    private ActivityImageVpBinding db;

    public ImageActivityAdapter(Context context, List<String> list) {
        super(context, list);
        views = new View[list.size()];
    }


    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        db = DataBindingUtil.inflate(inflater, R.layout.activity_image_vp, container, false);
        db.setEvent(((ImageActivity) context));
      /*  Glide.with(context).load(list.get(position)).into(new SimpleTarget<GlideDrawable>() {
            @Override
            public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
                db.iv.setImageDrawable(resource);
            }
        });*/

        Glide.with(context).load(list.get(position)).skipMemoryCache(true).into(db.iv);
        Log.e("ImageActivityAdapter", "instantiateItem: " + position);
        views[position] = db.getRoot();
        container.addView(db.getRoot());
        return db.getRoot();
    }

    @Override
    public void notifyDataSetChanged() {
        views = new View[list.size()];
        super.notifyDataSetChanged();
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(views[position]);
    }
}
